<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>System Control Tools</title>
    <!-- 引用vue和elementUI-->
    <!--    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">-->
    <!--    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
    <!--    <script src="https://unpkg.com/element-ui/lib/index.js"></script>-->
    <link rel="stylesheet" href="./js/index.css">
    <script src="./js/vue.js"></script>
    <script src="./js/index.js"></script>
    <script src="./js/axios.min.js"></script>
</head>
<body>
<div id="app">
    <div>
        <el-input type="textarea" style="width: 40%; height:150px; margin: 10px 30px;" :rows=6 v-model="inputStr" placeholder="输入脚本"></el-input>
        <el-button type="success" style="width: 40%; height:150px; margin: 10px 30px;" @click="execute(inputStr)">执行脚本</el-button>
        <el-button type="success" style="width: 40%; height:150px; margin: 10px 30px;" @click="execute('taskkill /im chrome.exe')">关闭浏览器</el-button>
        <el-button type="success" style="width: 40%; height:150px; margin: 10px 30px;" @click="execute('shutdown -s -t 0')">直接关机</el-button>
        <el-button type="success" style="width: 40%; height:150px; margin: 10px 30px;" @click="dialogVisible = true">定时关机</el-button>
        <el-button type="success" style="width: 40%; height:150px; margin: 10px 30px;" @click="execute('shutdown /a')">取消定时关机</el-button>
        <el-button type="success" style="width: 40%; height:150px; margin: 10px 30px;" @click="execute('rundll32.exe user32.dll LockWorkStation')">锁屏</el-button>
        <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
            <el-input type="text" v-model="shutMinutes" placeholder="输入定时关机分钟数"></el-input>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="shut">确 定</el-button>
            </span>
        </el-dialog>
        <el-button type="success" style="width: 40%; height:150px; margin: 10px 30px;" @click="dialogVisibleKill = true">杀死进程</el-button>
        <el-dialog title="提示" :visible.sync="dialogVisibleKill" width="30%">
            <el-input type="text" v-model="taskName" placeholder="输入进程名称,一般为exe结尾"></el-input>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisibleKill = false">取 消</el-button>
                <el-button type="primary" @click="kill">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</div>
<script type="text/javascript">
    const vm = new Vue({
        el: '#app',
        data: {
            batPath: "",
            inputStr: "",
            dialogVisible: false,
            dialogVisibleKill: false,
            shutMinutes: null,
            taskName: null
        },
        methods: {
            execute(script) {
                if (!script) this.$message({type: 'error', message: "请输入脚本"});
                let url = "./execute?script=" + script;
                axios.get(url).then(res => {
                    this.$message({type: 'success', message: res.data})
                })
            },
            shut() {
                if(!this.shutMinutes) this.$message({type: 'error', message: "请输入定时关机分钟数"});
                this.dialogVisible = false;
                this.execute("shutdown -s -t " + this.shutMinutes * 60);
            },
            kill() {
                if(!this.taskName) this.$message({type: 'error', message: "请输入进程名称"});
                this.dialogVisibleKill = false;
                this.execute("taskkill /im " + this.taskName);
            }
        }
    })
</script>
</body>
</html>